package com.pearadmin.modules.sys.service.impl;

import com.pearadmin.common.tools.MailUtil;
import com.pearadmin.modules.sys.domain.SysCustomer;
import com.pearadmin.modules.sys.dto.CustomerSubmitDTO;
import com.pearadmin.modules.sys.mapper.SysCustomerMapper;
import com.pearadmin.modules.sys.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {


    @Resource
    SysCustomerMapper customerMapper;

    @Autowired
    private MailUtil mailUtil;

    @Override
    public List<SysCustomer> findAll() {
        return customerMapper.selectList();
    }

    @Override
    public Integer save(SysCustomer sysCustomer) {
        //保存后的返回值对象，此时没有加时间戳，待下次查询时就有了，说明加在了Insert之后
        int insert = customerMapper.insert(sysCustomer);
        return insert;
    }

    public void submitAndEmail(CustomerSubmitDTO data){
        SysCustomer sysCustomer = new SysCustomer();
        sysCustomer.setCompanyName(data.getName());
        sysCustomer.setCustomerName(data.getYName());
        sysCustomer.setCustomerPhone(data.getPhone());

        //客户提交的信息需先保存入库
        this.save(sysCustomer);

        //测试环境隐藏
        mailUtil.sendMail(data, null);
    }
}
